<template>
  <div>
    <div id="div3">
      <el-table
          :data="tableData1"
          border
          style="width: 100%">
        <el-table-column
            label="标题"
            prop="title"
            width="675">
        </el-table-column>
        <el-table-column
            label="操作"
            width="350">
          <template #default="scope">
            <el-button @click="showcontent(scope.row)">查看</el-button>
            <el-button @click="detelenotice(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>


      <el-dialog v-model="orderInfo1" title="内容" :before-close="close2" >
        <template #footer>
          <div >
            <p class="content1">内容:{{tableData2.content}}</p>
          </div>
        </template>
          <el-button @click="close1()" class="content-b">关闭</el-button>
      </el-dialog>

    </div>
    <el-button type="primary" id="button1" @click="release()">发布公告</el-button>
    <el-dialog v-model="orderInfo2" title="新的公告" :before-close="close2" class="dialog1">
      <el-form-item label="公告名称" >
        <el-input v-model="title"></el-input>
      </el-form-item>
      <el-form-item label="公告内容">
        <el-input type="textarea"  v-model="content"></el-input>
      </el-form-item>
      <el-button type="primary" @click="releasenotice()">发布</el-button>
      <el-button @click="close2()">关闭</el-button>
    </el-dialog>
  </div>
</template>

<script>
import request from "@/utils/request";
import router from "@/router";
import row from "element-ui/packages/row";

export default {
  name: "OrderHistory",
  data(){
    return{
      orderInfo1:false,
      orderInfo2:false,
      tableData1: [],
      tableData2: {
        title:'',
        content:'',
      },
      readorder:false,
      action: {},
      goods: {},
      user: {},
      input2:[],
      title: '',
      content: '',
    }
  },

  methods:{
    formatData(row, column, cellValue, index){
		
		//把传过来的日期进行回炉重造一下，又创建了一个js的 Date对象，进行重新构造，转为String字符串
		//最终返回 s 就可以了
		var s =	new Date(cellValue).toLocaleString();
	return s;
 },
    getOrders() {
      request.get("http://localhost:8082/order/viewOrders").then(res => {
        if (res.flag) {
          this.tableData = res.data['order2s']
          this.user = res.data['user']
          this.$message({
            type: 'success',
            message: res.msg
          });
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    releasenotice(){
        request.post("http://localhost:8081/seller/notice?title="+this.title+"&content="+this.content).then(res =>{
          if (res.flag) {
            this.$message({
              type: 'success',
              message: res.msg
            })
          }
          else {
            this.$message.error(res.msg);
          }
        })
    },
    shownotice(){
      request.get("http://localhost:8081/seller/shownotice").then(res => {
        if (res.flag) {
          this.tableData1 = res.data;
          this.$message({
            type: 'success',
            message: res.msg
          })
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    showcontent(row){
      this.orderInfo1=true;
      this.id=row.id
      request.get("http://localhost:8081/seller/checkcontentbyid?id="+this.id).then(res => {
        if (res.flag) {
          this.tableData2 = res.data;
          console.log('ghh',this.tableData2);
          this.$message({
            type: 'success',
            message: res.msg
          })
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    detelenotice(row){
      this.id=row.id;
      request.get("http://localhost:8081/seller/detelenotice?id="+this.id).then(res => {
        if (res.flag) {
          this.tableData2 = res.data;
          this.$message({
            type: 'success',
            message: res.msg
          })
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    Showorder(data){
      this.action = data.action
      this.goods = data.goods
      this.readorder=true;
    },
    close1() {
      this.orderInfo1 = false;
    },
    close2() {
      this.orderInfo2 = false;
    },
    release(){
      this.orderInfo2=true;
    }
  },
  created() {
    this.getOrders();
    this.shownotice();
  },

}
</script>

<style scoped>
#div3 {
  position: absolute;
  left: 20%;
  right:10%;
  top: 15%;
  bottom: 40%;
  background: linear-gradient(to bottom right, #ffffff, #ffffff, #f6f6f6);
  border: 3px inset rgb(27, 28, 27);
}
#button1{
  position: absolute;
  top:60%;
  left:84%;
}
.dialog1{
  z-index: 2;
}
.content1{
  position: absolute;
  top: 100px;
  left:4%;
}
.content-b{
  margin-top: 100px;
}
</style>
